package com.example.ineedahelp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.EditText;

import com.netmera.mobile.NetmeraCallback;
import com.netmera.mobile.NetmeraException;
import com.netmera.mobile.NetmeraUser;

public class RegisterActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
	
		setContentView(R.layout.activity_register);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.register, menu);
		return true;
	}
	
	
	public void register(View view) {
		final EditText email = (EditText)findViewById(R.id.email);
		final EditText password = (EditText)findViewById(R.id.password);
		final EditText repassword = (EditText)findViewById(R.id.repassword);
		if( password.getText().toString().equals(repassword.getText().toString())){
			
			NetmeraUser user = new NetmeraUser();
			user.setEmail(email.getText().toString());
			user.setPassword(password.getText().toString());
			user.setNickname(email.getText().toString().substring(0, user.getEmail().indexOf("@")));
			user.setName("testName");
			user.setSurname("testSurname");

				//user.register();
				user.registerInBackground(new NetmeraCallback< NetmeraUser>() {
				    @Override
				    public void callback(NetmeraUser result, NetmeraException exception) {
				        if (result != null && exception == null) {
			                Intent intent = new Intent(getApplicationContext(),HelpActivity.class);
			                startActivity(intent);
				        } else {

				        }       
				    }
				});


		}
	}

}
